﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using eShop.Business;
using eShop.Model;
using eShop.DataAccess;

namespace eShop.Business
{
    public class ProductStockManager
    {
        public static void Create(ProductStock stock)
        {
            ProductStockDAO.Save(stock);
        }

        public static void Update(ProductStock productStock)
        {
            ProductStock tblProductStock = null;
            if (productStock.StockId > 0)
            {
                tblProductStock = ProductStockDAO.GetTblProductStockByStockId(productStock.StockId);
            }
            else
            {
                tblProductStock = new ProductStock();
            }
            if (tblProductStock != null)
            {
                tblProductStock.ProductId = productStock.ProductId;
                tblProductStock.Description = productStock.Description;
                tblProductStock.Weight = productStock.Weight;
                tblProductStock.WeightUnit = productStock.WeightUnit;
                tblProductStock.StockAvailable = productStock.StockAvailable;
                tblProductStock.StockAlertCount = productStock.StockAlertCount;
                ProductStockDAO.Save(productStock);
            }
        }

        public static List<ProductStock> GetStockByProductId(int productId)
        {
            return ProductStockDAO.GetProductStockByProductId(productId);
        }

        public static ProductStock GetStockById(int stockId)
        {
            return ProductStockDAO.GetTblProductStockByStockId(stockId);
        }

        public static bool Delete(int productStockId)
        {
            return ProductStockDAO.DeleteTblProductStock(productStockId);
        }

        public static List<ProductStock> GetStockOutItemsPaged(int stockLevel, string orderBy, int startRow, int pageSize)
        {
            return ProductStockDAO.GetStockOutItemsPaged(stockLevel, orderBy, startRow, pageSize);
        }
    }
}
